package com.leyou.page.web;


import com.leyou.page.service.PageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Slf4j
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    @GetMapping("item/{id.html")
    public String toItemPage(@PathVariable("id") Long spuId, Model model) {
        log.info("[page 服务，接受到的sku的spuId为:{}]", spuId);
        // 添加数据
        Map<String, Object> attributes = pageService.loadModel(spuId);
        // 准备模型数据
        model.addAllAttributes(attributes);
        return "item";
    }
}
